package edu.nf.project.services.listener;

import edu.nf.project.services.task.SelfInspectionTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @author CSY
 * @date 2025 - 06 - 16
 * 项目启动监听器 - 用于在项目启动时执行操作
 */
@Component
public class ApplicationStartupListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private SelfInspectionTask selfInspectionTask;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        //避免多次触发
        if(event.getApplicationContext().getParent() == null){
            //程序启动时判断是否需要添加自检记录
            selfInspectionTask.checkAndExecute();
        }
    }
}
